/*
 * Licensed to the 南京汇海交通科技有限公司
 *
 * Copyright (c) 2025.
 * All rights reserved.
 *
 * 本软件属南京汇海交通科技有限公司所有，在未获得南京汇海交通科技有限公司正式授权情况下，任何企业和个人，不能获取、阅读、安装、传播本软件涉及的任何受知识产权保护的内容。
 */
package com.chframework.common.context;

import org.springframework.context.SmartLifecycle;

public abstract class BeanLifecycle implements SmartLifecycle {
    //region spring容器初始化完成之后执行
    protected void initMethod() {
    }

    protected void destroyMethod() {
    }
    //endregion

    //region SmartLifecycle
    private boolean runState = false;

    //step 3
    @Override
    public boolean isRunning() {
        return this.runState;
    }

    //step 5
    @Override
    public void start() {
        this.initMethod();
        runState = true;
    }

    //step 7
    @Override
    public void stop() {
        this.destroyMethod();
        this.runState = false;
    }

    //step 1 & 4
    @Override
    public boolean isAutoStartup() {
        return true;
    }

    //step 6
    @Override
    public void stop(Runnable callback) {
        this.stop();
        callback.run();
    }

    //step 2
    @Override
    public int getPhase() {
        return Integer.MAX_VALUE;
    }
    //endregion
}
